package com.google.code.virtualhockey.vhx.server.model

import com.google.code.virtualhockey.vhx.sds.fields._
import com.google.appengine.api.datastore.{GeoPt, Entity}
import com.google.code.virtualhockey.vhx.sds.{SNameKey, SKey, STMetaData, STNamedEntity}

/**
 * Represents a club that participates in a VHX game.
 */
class Club( cpCode: String,
            val union: SKey[NationalUnion],
            val name: String,
            val nameOfficial: String,
            val place: String,
            val country: String,
            val location: GeoPt ) extends STNamedEntity[Club] {

  setEntityName( cpCode )

  /** Private no-arg constructor for SDS. */
  private def this() = this( null, null, null, null, null, null, null )
}

object ClubMeta extends STMetaData[Club] {
  val cls = classOf[Club]
  val kind = "Club"
  val fields = List(
    new SKeyField( this, "union" ),
    new SShortText( this, "name", true ),
    new SShortText( this, "nameOfficial", false ),
    new SShortText( this, "place", false ),
    new SShortText( this, "country", false ),
    new SGeoPoint( this, "location", false ) )

  /**
   * Creates a new Club instance from a CSV file line.
   */
  override def fromCsv( values: List[Any] ): Club = {
    new Club( values(0).toString,
              new SNameKey[NationalUnion]( values(1).toString ),
              values(2).toString,
              values(3).toString,
              values(4).toString,
              values(5).toString,
              new GeoPt( values(6).asInstanceOf[Float], values(7).asInstanceOf[Float] ) )
  }
}
